import React from 'react'
import { Layout} from 'antd';
import Table from '../Table'
import Editor from "../Editor"
import {useSelector,useDispatch,connect} from 'react-redux'
import "./tr.css"

const {Content} = Layout;

const Check = () => {
  const checkList = useSelector(state=> state.check.checkList)
  const valueList = useSelector(state=> state.value.valueList)
  const dispatch = useDispatch()
  let value;
  
  const columns = [
    {
        title: '打卡id',
        key: 'check_id',
        dataIndex: 'check_id',
        valueType: 'text',
    },
    {
      title: '打卡用户头像',
      key: 'checkuser_img',
      dataIndex: 'checkuser_img',
      valueType: 'avatar',
      hideInSearch:true
    },
    {
        title: '打卡用户名',
        dataIndex: 'checkuser_name',
        key: 'checkuser_name',
        ellipsis:true
    },
    {
      title: '打卡主题',
      key: 'check_topic',
      dataIndex: 'check_topic',
      valueType: 'text',
    },
    {
      title: '打卡内容',
      key: 'check_content',
      dataIndex: 'check_content',
      valueType: 'text',
    },
    {
      title: '打卡日期',
      key: 'check_time',
      dataIndex: 'check_time',
      valueType: 'text',
    },
    {
      title: '打卡图片',
      key: 'check_img',
      dataIndex: 'check_img',
      valueType: 'avatar',
      hideInSearch:true
    },
    {
      title: '用户账号',
      key: 'user_number',
      dataIndex: 'user_number',
      valueType: 'text',
    },
    {
        title: '操作',
        key: 'option',
        width: 120,
        valueType: 'option',
        render: (text,record,index,action) => [<div onClick={()=>{
          dispatch({type:'get',con:record});console.log(valueList)
        }}><Editor ques={user} url="http://101.34.58.111:8081/checkmes"/></div>
        , <a onClick={async ()=>{
          console.log(record)
          await fetch(`http://101.34.58.111:8081/checkmes/${record.check_id}`,{
          method:'delete',
          headers: {
            'Content-Type': 'application/json;charset=UTF-8'
          },
          // body:JSON.stringify(record)
        })
        dispatch({type:'delete',content:['delete']})
        }}>删除</a>]
      }];
  const right = {}

  const user = [
    {name:'check_id',label:'打卡id',tooltip:'最长为24位',placeholder:'请输入打卡id'},
    {name:'checkuser_name',label:'打卡用户名',tooltip:'最长为24位',placeholder:'请输入打卡用户名称'},
    {name:'checkuser_img',label:'打卡用户头像',placeholder:'上传头像'},
    {name:'check_topic',label:'打卡主题',tooltip:'最长为24位',placeholder:'请输入打卡主题'},
    {name:'check_content',label:'打卡内容',tooltip:'最长为24位',placeholder:'请输入打卡内容'},
    {name:'check_time',label:'打卡日期',tooltip:'最长为24位',placeholder:'请输入打卡日期'},
    {name:'check_img',label:'打卡图片',placeholder:'上传图片'},
    {name:'user_number',label:'用户账号',tooltip:'最长为24位',placeholder:'请输入用户账号'}
]

    return (
        <Content className="site-layout-background" style={{paddingLeft: 10,margin: 0,minHeight: 280,}}>
          <Table title="打卡管理" columns={columns} right={right} url="http://101.34.58.111:8081/checkmes" ques={user} />
        </Content>
    )
}

export default connect()(Check)